package com.wchat.repository;

import com.wchat.dataobject.VerifyCodeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

public interface VerifyCodeRepository extends JpaRepository<VerifyCodeEntity,Integer> {

      VerifyCodeEntity findByPhoneNumber(String phoneNumber);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update verify_code v set v.verify_Code = ?1 where v.phone_Number = ?2",nativeQuery = true)
    int updateVerifyCodeByPhoneNumber(@Param("verifyCode") int verifyCode, @Param("phonneNumber") String phonneNumber);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update verify_code v set v.is_Used = ?1 where v.phone_Number = ?2",nativeQuery = true)
    int updateIsUsedByPhoneNumber(@Param("isUsed") int isUsed, @Param("phonneNumber") String phonneNumber);



}
